package com.xrh.core.generater.utils;

import org.apache.commons.lang3.StringUtils;

import com.xrh.core.generater.bean.UserInput;
import com.xrh.core.generater.interfaces.MarkReplaceInf;

import lombok.Getter;

/**
 * @function 标记枚举
 * @author 肖荣辉
 * @date 2021年7月26日
*/
@Getter
public enum MarkEnum {
	
	/****************************** 通用标记start ******************************/
	AUTHOR_NAME("程序员名字标记"),
	
	GENERATE_DATE_MARK("生成日期标记"),
	
	ADD_REQUEST_PACKAGE_MARK("addRequest包路径标记"),
	
	UPDATE_REQUEST_PACKAGE_MARK("updateRequest包路径标记"),
	
	QUERY_REQUEST_PACKAGE_MARK("queryRequest包路径标记"),
	
	ENTITY_PACKAGE_MARK("entity包路径标记"),
	
	DTO_PACKAGE_MARK("dto包路径标记"),
	
	CONTROLLER_PACKAGE_MARK("controller包路径标记"),
	
	DAO_PACKAGE_MARK("dao包路径标记"),
	
	SERVICE_PACKAGE_MARK("service包路径标记"),
	/****************************** 通用标记end ******************************/
	
	/****************************** 特殊标记start ******************************/
	BIG_ENTITY_NAME_MARK("mongo entity 未处理后缀的首字母大写全名称"),
	
	SMALL_ENTITY_NAME_MARK("mongo entity 未处理后缀的首字母小写全名称"),
	
	MONGO_QUERY_TXT_MARK("mongo queryRequest createQuery 方法内的查询标记"),
	
	MYBATIS_QUERY_TXT_MARK("mybatis plus queryRequest createQuery 方法内的查询标记"),
	
	TABLE_NAME_MARK("表名标记"),
	
	TABLE_COMMENT_MARK("表备注标记"),
	
	PRIVATE_PROPERTY_MARK("私有属性文本标记"),
	
	BIG_CLASS_NAME_MARK("类名首字母大写标记") ,
	
	SMALL_CLASS_NAME_MARK("类名首字母小写标记"),
	
	PRIVATE_PROPERTY_COMMENT_MARK("属性备注标记"),
	
	API_MODEL_PROPERTY_MARK("属性api注解标记"),
	
	PROPERTY_JAVA_TYPE_NAME_MARK("属性java类型名称标记"),
	
	PROPERTY_NAME_MARK("属性名称标记");
	/****************************** 特殊标记end ******************************/
	
	private MarkEnum(String comment) {
		this.comment = comment;
	}

	//标记备注
	private String comment;
	
	public static String replace(MarkEnum markEnum , String text  , String newChar){
		
		if(StringUtils.isNotBlank(newChar))
			return	text.replaceAll("##"+markEnum.name()+"##" , newChar);
		
		return text;
	}
	
	/**
	 * @function 替换标记
	 * @author 肖荣辉
	 * @date 2021年7月26日
	*/
	public static String replaceMark(String txt , UserInput userInput , MarkReplaceInf markReplaceInf) {
		
		txt = replace(MarkEnum.AUTHOR_NAME , txt , userInput.getAuthorName());
		
		txt = replace(MarkEnum.GENERATE_DATE_MARK , txt , DateUtils.getTimeNow());
		
		txt = replace(MarkEnum.ADD_REQUEST_PACKAGE_MARK , txt , userInput.getAddRequestPackage());
		
		txt = replace(MarkEnum.UPDATE_REQUEST_PACKAGE_MARK , txt , userInput.getUpdateRequestPackage());
		
		txt = replace(MarkEnum.QUERY_REQUEST_PACKAGE_MARK , txt , userInput.getQueryRequestPackage());
		
		txt = replace(MarkEnum.ENTITY_PACKAGE_MARK , txt , userInput.getEntityPackage());
		
		txt = replace(MarkEnum.DTO_PACKAGE_MARK , txt , userInput.getDtoPackage());
		
		txt = replace(MarkEnum.CONTROLLER_PACKAGE_MARK , txt , userInput.getControllerPackage());
		
		txt = replace(MarkEnum.DAO_PACKAGE_MARK , txt , userInput.getDaoPackage());
		
		txt = replace(MarkEnum.SERVICE_PACKAGE_MARK , txt , userInput.getServicePackage());
		
		/*特殊标记替换*/
		txt = replace(MarkEnum.BIG_CLASS_NAME_MARK , txt , markReplaceInf.getBigClassName());
		txt = replace(MarkEnum.SMALL_CLASS_NAME_MARK , txt , markReplaceInf.getSmallClassName());
		txt = replace(MarkEnum.TABLE_NAME_MARK , txt , markReplaceInf.getTableName());
		
		//剔除那个表字
		String comment = markReplaceInf.getTableComment();
		comment =	 StringUtils.isNotBlank(comment) && comment.endsWith("表") && comment.length() > 1 ? comment.substring(0 , comment.length() - 1) : comment;
		txt = replace(MarkEnum.TABLE_COMMENT_MARK , txt , comment);
		
		return txt;
		
	}
	
	
	
}
